import PageTemplate from '@/components/common/PageTemplate'
import PersonSelect from '@/components/asc/PersonSelect'
import {addDelegates,getCurrentUserDetail} from '@/api/api'
import store from '@/store'
import * as Constant from '@/utils/constant'

export default {
    components:{
      PageTemplate,
        PersonSelect
    },
    data() {
        return {
            brand:[
                {name:'lang.work_delegate'},
                {name:'cm.add'},
            ],
            hasIcon:false,
            showCollapse:'collapse',
            delegate:{
                procName: store.state.proc.procName,
                procFullName: store.state.proc.procFullName,
                procId:store.state.proc.procId,
                man:this.$root.NOW_USER,
                delegateUser:'',
                delegateUserId:'',
                beginTime:'',
                endTime:''
            }
        }
    },
    methods: {
        //保存代理
        saveDelegate:function(formName){
            //获取受托人
            let user = document.getElementById("delegateUser").value;
            this.delegate.delegateUserId = user.substr(1,user.indexOf(']')-1);
            this.delegate.delegateUser = user.substr(user.indexOf(']')+1);
            this.$refs[formName].validate((valid)=>{
                if(valid){
                    let _this = this;
                    addDelegates(this.delegate).then((result) => {
                        if(result.status == "200" || result.data.code == "0"){
                            _this.$router.push(Constant.ROUTE_WORK_DELEGATE.index);
                        }else{
                            _this.$alert(result.data.msg,_this.$t('cm.tips'));
                        }
                    }).catch((err) => {
                        _this.$alert(err,_this.$t('cm.tips'));
                    });
                }else{
                    return false;
                }
            });
        },
        //回退
        goBack:function(){
            this.$router.back()
        },
        getNowUser(){
            let _this = this;
            //console.log("work_delegates_add---63--",_this);
            getCurrentUserDetail({}).then((result) => {
            if (result.status == "200" && result.data.code == "0") {
                //delegate
                //_this.delegate.procName=result.data.data.userName;
                _this.delegate.man = result.data.data.userName;
                //console.log("work_delegates_add---66--",result.data.data.userName);
                //console.log("work_delegates_add---67-_this.delegate.procName-",_this.delegate.man);

            } else {
                _this.$alert(result.data.msg, _this.$t('cm.tips'));
            }
            }).catch((err) => {
            _this.$alert(err,_this.$t('cm.tips'));
            });
        }
    },
    created() {
      this.getNowUser();
    },
    computed: {
        delegateRules:function(){
            return {

            };
        }
    },

}
